package net.aaa.hotel.controller;

import com.alibaba.fastjson.JSON;
import net.aaa.hotel.dao.PanDao;
import net.aaa.hotel.dao.impl.PanDaoImpl;
import net.aaa.hotel.entity.PageInfo;
import net.aaa.hotel.util.LayuiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pan")
public class PanSpringController {
    @Autowired
    private PanDao dao = new PanDaoImpl();

    @RequestMapping("/queryS")
    public LayuiTable query(PageInfo pageInfo) {

        List<Map> maps = dao.queryS(pageInfo);

        int a = dao.queryN();

        LayuiTable la = new LayuiTable(a, maps);

        return la;
    }
    @RequestMapping("/queryP")
    public LayuiTable queryP(PageInfo pageInfo) {

        List<Map> maps = dao.queryP(pageInfo);
        int a = dao.queryPN();

        LayuiTable la = new LayuiTable(a, maps);

        return la;
    }
    @RequestMapping("/pank")
    public int pank(HttpServletRequest request){
        Map data = (Map)JSON.parse(request.getParameter("data"));
       int i =  dao.addPan(data);
       int a=0;
       int b=0;
        List<Map> pantable = (List<Map>) JSON.parse(request.getParameter("pantable"));
        for (Map map : pantable) {
            if (map.get("ssCount") != null) {

             a += dao.addPD(map,i);
             b+= dao.addPS(map);
            }else {
                a+=dao.addPd(map,i);
            }
        }

        return a;
    }
    @RequestMapping("/queryId")
    public  LayuiTable queryId(Integer id,PageInfo pageInfo){
        List<Map> maps = dao.queryId(id,pageInfo);
        int a = dao.queryC(id);
        LayuiTable la = new LayuiTable(a,maps);
        return la;
    }
}
